home *** CD-ROM | disk | FTP | other *** search
- /*
- ----------- D E M O . C
-
- May 1989 - HA OLIVER
- */
-
-
- #include "Demo.h"
-
- /*
- ---------------------- Globals...
- */
-
- TEHandle CurrentText;
- ListHandle CurrentList;
- WindowPtr CurrentPort;
- Handle ListList,TextList,PictList;
- SysEnvRec theWorld;
- MenuHandle myMenus[LastMenu];
- CursHandle IbeamHdl,WatchHdl,PlusHdl,CrossHdl;
- Cursor Ibeam,Watch,Plus,Cross;
- Boolean MultiFinder,notFinished=TRUE,isDoc=FALSE;
- EventRecord Event;
- char theChar;
- Rect dragRect = { 0, 0, 1024, 1024 },growRect = { 0, 0, 1024, 1024 };
-
-
- /*
- ---------------------- SetUp the Cursors
- */
-
- SetUpCursor()
- {
- WatchHdl =GetCursor(watchCursor);
- IbeamHdl =GetCursor(iBeamCursor);
- CrossHdl =GetCursor(crossCursor);
- PlusHdl =GetCursor(plusCursor);
- Watch =**WatchHdl;
- Ibeam =**IbeamHdl;
- Cross =**CrossHdl;
- Plus =**PlusHdl;
- }
-
- /*
- ---------------------- Set Up the Menu Bar
- */
-
- SetUpMenus()
- {
- register int i;
-
- myMenus[1] = GetMenu(AppleM);
- myMenus[2] = GetMenu(FileM);
- for ( (i=1); (i<=LastMenu); i++ ) InsertMenu(myMenus[i], 0);
- DrawMenuBar();
- }
-
- /*
- ---------------------- SetUp the System
- */
-
- SetUpSystem()
- {
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NULL);
- InitAllPacks();
- InitCursor();
- MaxApplZone();
- MoreMasters();
- MoreMasters();
- MoreMasters();
- MoreMasters();
- MoreMasters();
- FlushEvents(everyEvent,0);
- }
-
- /*
- ---------------------- SetUp some Variables ...
- */
-
- SetUpVariables()
- {
- CurrentText =NULL;
- CurrentList =NULL;
- if (GetTrapAddress(WaitNextEventTrap)==GetTrapAddress(UnImplementedTrap))
- MultiFinder=FALSE;
- else
- MultiFinder=TRUE;
- if (SysEnvirons(1,&theWorld)!=envNotPresent)
- {
- }
- else notFinished=FALSE;
- }
-
- /*
- ---------------------- Adjust Cursor form
- */
-
- MaintainCursor()
- {
- WindowPtr theWindow;
- Point pt,newOr;
- Rect contRect;
- Cursor theCursor;
- Boolean changed;
-
- changed =FALSE;
- theWindow=FrontWindow();
- GetPort(&CurrentPort);
- SetPort(theWindow);
- GetWindowClip(&contRect,&newOr,theWindow);
- OffsetRect(&contRect,newOr.h,newOr.v);
- GetMouse(&pt);
- if (PtInRect(pt,&contRect))
- {
- ClipRect(&contRect);
- SetOrigin(newOr.h,newOr.v);
- if (FindText(pt,theWindow)!=NULL)
- { theCursor=Ibeam;
- changed =TRUE;
- }
- if (FindList(false,pt,theWindow)!=NULL)
- { theCursor=Plus;
- changed =TRUE;
- }
- }
- if (changed)
- SetCursor(&theCursor);
- else
- SetCursor(&arrow);
- SetPort(CurrentPort);
- }
-
- /*
- ---------------------- How many bytes are free ?
- */
-
- CheckMemory()
- {
- }
-
- /*
- ---------------------- Adjust all Menus
- */
-
- MaintainMenu()
- {
- }
-
- /*
- ---------------------- The Event Loop !
- */
-
- doLoop()
- {
- WindowPtr inWindow;
- int where;
- Boolean eventOK;
-
- SystemTask();
- if (CurrentText!=NULL) TEIdle(CurrentText);
- if (isDoc) MaintainCursor();
- MaintainMenu();
- CheckMemory();
-
- if (MultiFinder)
- eventOK=WaitNextEvent(everyEvent,&Event,sleep,NULL);
- else
- eventOK=GetNextEvent(everyEvent,&Event);
-
- where=FindWindow(Event.where,&inWindow);
-
- if (eventOK)
- {
- switch (Event.what)
- { case nullEvent :break;
- case mouseDown :{
- switch (where)
- {
- case inMenuBar :doMenu(MenuSelect(Event.where));break;
- case inSysWindow :SystemClick(&Event,inWindow);break;
- case inDesk :break;
- default :ExecWindow(&Event,inWindow);break;
- }
- };break;
-
- case keyDown :
- case keyUp :
- case autoKey :{
- theChar = Event.message & charCodeMask;
- if ((Event.modifiers & cmdKey) != 0)
- doMenu(MenuKey(theChar));
- else
- if(inWindow!=NULL)
- ExecWindow(&Event,inWindow);
- };break;
- case diskEvt :
- case driverEvt :break;
- case multiFinderEvt :if (FrontWindow()!=NULL) ExecWindow(&Event,FrontWindow());break;
- case activateEvt :
- case updateEvt :ExecWindow(&Event,Event.message);break;
- }
- }
- }
-
- /*
- ---------------------- the main() ...
- */
-
- main()
- {
- SetUpSystem();
- SetUpVariables();
- SetUpCursor();
- SetUpMenus();
-
- while(notFinished)
- {
- doLoop();
- }
- }
-
- /*
- ----------------------
- */
-
-